package com.acoffee.service.Impl;

import com.acoffee.mapper.RbacManageeMapper;
import com.acoffee.pojo.Dto;
import com.acoffee.pojo.RbacManager;
import com.acoffee.service.RbacManagerService;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author acoffee
 * @create 2021-11-25 18:50
 */
@Service
public class RbacManagerServiceImpl implements RbacManagerService {

    @Autowired
    RbacManageeMapper rbacManageeMapper;

    @Override
    public List<RbacManager> queryAll(Dto dto) {
        List<RbacManager> rbacManagers = rbacManageeMapper.queryAll(dto);
        return rbacManagers;
    }

    @Override
    public RbacManager queryOne(int id) {
        RbacManager manager = rbacManageeMapper.queryOne(id);
        return manager;
    }

    @Override
    public boolean addOne(RbacManager manager) {
        //添加用户时密码加密处理
        String password = manager.getPassword();
        //MD5加盐加密
        SimpleHash simpleHash = new SimpleHash("MD5", password, manager.getAccount() + "acoffee");
        //转换成十六进制
        String newPassword = simpleHash.toHex();
        manager.setPassword(newPassword);

        boolean flag = rbacManageeMapper.addOne(manager);
        return flag;
    }

    @Override
    public boolean updateOne(RbacManager manager) {
        boolean flag = rbacManageeMapper.updateOne(manager);
        return flag;
    }

    @Override
    public boolean deleteOne(int id) {
        boolean flag = rbacManageeMapper.deleteOne(id);
        return flag;
    }
}
